<template>
  <div class="item" @click="linkDetail">
    <img class="icon" src="@/assets/common/text-icon.png" />
    <div class="content">
      <div class="title-wrap">
        <div class="title">{{ content.title }}</div>
        <div class="tag" v-if="content.isSubmit == '0'">未提交</div>
      </div>
    </div>
    <div class="btn-group">
      <img v-if="content.status == '1'" class="btn" @click.stop="onEdit" src="@/assets/common/edit-icon.png" />
      <img v-if="content.status == '1'" class="btn" @click.stop="onDel" src="@/assets/common/delete-icon.png" />
      <img v-if="content.status == '2'" class="arrow" src="@/assets/common/arrow-right-blue.png" />
    </div>
  </div>
</template>

<script>
import { deleteAnnualReport } from "@/api/annualReport";
import { Dialog, Toast } from "vant";
export default {
  props: {
    content: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {};
  },
  methods: {
    linkDetail() {
      if (this.content.status == "1") {
        this.onEdit();
      } else {
        this.$router.push({
          path: "/annualReport/detail",
          query: {
            id: this.content.id
          }
        });
      }
    },
    onEdit() {
      if (this.content.isFlag) {
        this.$router.push({
          path: "/annualReport/add",
          query: {
            id: this.content.id
          }
        });
      } else {
        Toast("当前周期已结束，无法编辑");
      }
    },
    onDel() {
      Dialog.confirm({
        title: "删除",
        message: "确定删除该记实吗？"
      })
        .then(() => {
          deleteAnnualReport(this.content.id).then(res => {
            if (res.data) {
              this.$emit("onDel");
            } else {
              Toast(res.msg);
            }
          });
        })
        .catch(() => {
          // on cancel
        });
    }
  }
};
</script>

<style scoped lang="scss">
.item {
  display: flex;
  align-items: center;
  background: #fff;
  padding: 20px;
  margin-bottom: 16px;
  border-radius: 8px;
  &:active {
    background: #f9f9f9;
  }
  .icon {
    width: 30px;
    margin-right: 18px;
  }
  .content {
    flex: 1;
  }
  .title-wrap {
    display: flex;
    font-size: 14px;
    .tag {
      width: 40px;
      line-height: 18px;
      height: 18px;
      border-radius: 2px;
      background: #f0f0f0;
      margin-left: 6px;
      text-align: center;
      color: #cccccc;
      font-size: 10px;
    }
  }
  .time {
    line-height: 17px;
    margin-top: 3px;
    font-size: 12px;
  }
  .btn-group {
    display: flex;
    align-items: center;
    .btn {
      width: 18px;
      margin-left: 14px;
    }
    .arrow {
      margin-right: 2px;
      height: 12px;
    }
  }
}
</style>
